
from whiff import whiffenv
from whiff import resolver
from whiff import gateway

def updateResource(env, start_response):
    env = resolver.process_cgi(env, parse_cgi=True)
    userid = whiffenv.cgiGet(env, "userid")
    password = whiffenv.cgiGet(env, "password")
    stringPath = whiffenv.cgiGet(env, "stringPath")
    currentValue = whiffenv.cgiGet(env, "currentValue")
    resourcePath = stringPath.split("/")
    try:
        gateway.putResource(env, resourcePath, currentValue)
    except gateway.AccessDenied:
        result = "access denied to resource %s: could not put value %s<br>\n" % (resourcePath, repr(currentValue))
    else:
        result = "put %s with value %s<br>\n" % (resourcePath, repr(currentValue))
    start_response("200 OK", [('Content-Type', 'text/html')])
    yield result
    yield '<a href="login?userid=%s&password=%s">return to login</a>' % (userid, password)

__wsgi__ = updateResource
